define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                  index_url: 'activity_sign/index/ids/'+Config.activity_id + location.search,
                    // add_url: 'question_format/add',
                    edit_url: 'activity_sign/edit',
                    // del_url: 'question_format/delete',
                    // multi_url: 'question_format/multi',
                    // import_url: 'question_format/import',
                    table: 'activity_sign',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showColumns:false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'id'},
                        {field: 'activity.title', title: '活動標題'},
                        {field: 'user.nickname', title: '用戶名'},
                          {field: 'user_id', title: '用戶ID'},
                            {field: 'vo_id', title: '義工ID'},
                              {field: 'vo.name', title: '姓名'},
                                {field: 'vo.birthday', title: '出生日期'},
                                  {field: 'vo.id_card_hk', title: '香港身份證號碼'},
                                    {field: 'vo.mobile', title: '香港手機號'},
                                    {field: 'vo.mobile_china', title: '內地手機號'},
                                    {field: 'vo.address', title: '地址'},
                                    {field: 'vo.wechat_id', title: '【微信ID'},

                        {field: 'create_time', title: '報名時間', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'sign_time', title: '簽到時間', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [
                                
                             {
                                    name: 'del',
                                    text: '删除',
                                    title: '删除',
                                    classname: 'btn btn-xs btn-info btn-ajax',
                                    icon: '',
                                    url: 'activity_sign/del',
                                    confirm: '确认删除吗?',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if ( Config.activity_del ) {
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function () {
                                                $(".btn-refresh").trigger("click");
                                            },
                                },
                                 {
                                    name: 'edit',
                                    text: '簽到',
                                    title: '簽到',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: '',
                                    url: 'activity_sign/edit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if ( Config.activity_edit ) {
                                            return true;
                                        }else{
                                            return false;
                                        }
                                         return true;
                                    }
                                },

                               
                               
                            ],
                        formatter: Table.api.formatter.buttons}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
          user_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activity_sign/user_list/ids/'+ Config.ids + location.search,
                    add_url: 'staff/add',
                    edit_url: 'staff/edit',
                    del_url: 'staff/del',
                    multi_url: 'staff/multi',
                    import_url: 'staff/import',
                    table: 'staff',
                }
            });

            var table = $("#table");
            $(".btn-add").data("area", ["100%", "100%"]);
            //当内容渲染完成给编辑按钮添加`data-area`属性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: false,
                search:false,
                showColumns:false,
                showExport:true,
                commonSearch:false,
                pageSize: 10,
                showToggle: false,
                exportOptions: {
                    fileName: '問卷記錄_' + Moment().format("YYYY-MM-DD"),  //导出名称
                    ignoreColumn: ['avatar'], //不导出字段
                    ignoreRow: [],
                    mso:{
                        // fileFormat:        'xlsx',
                        //修复导出数字不显示为科学计数法
                        onMsoNumberFormat: function (cell, row, col) {
                            return !isNaN($(cell).text())?'\\@':'';
                        }
                    },
                    csvSeparator: "----",//文本分割
                },
                columns: [
                    [
                        {checkbox: true},
                   

                  

                        {field: 'title', title: __('標題'), operate: 'LIKE'},

                         {field: 'create_time', title: __('填寫時間'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                     
                    ]
                ]
            });
              table.on("pre-body.bs.table",function(){
                var bt=table.data("bootstrap.table");
                if (bt){
                    bt.$toolbar.find(".export").find(".icon-share").text("導出");
                    bt.$toolbar.find(".export").find(".icon-share").removeClass("glyphicon glyphicon-export icon-share");
                }
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});


